<%@ page import="dao.Dao" %>
<%@ page import="domain.Goods" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: wangh
  Date: 2020/12/23
  Time: 13:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <!-- 指定字符集 -->
    <meta charset="utf-8">
    <!-- 使用Edge最新的浏览器的渲染方式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- viewport视口：网页可以根据设置的宽度自动进行适配，在浏览器的内部虚拟一个容器，容器的宽度与设备的宽度相同。
    width: 默认宽度与设备的宽度相同
    initial-scale: 初始的缩放比，为1:1 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>电脑销售平台</title>
    <!-- 1. 导入CSS的全局样式 -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="css/public.css">
    <link rel="stylesheet" type="text/css" href="css/reset.css">
    <link rel="stylesheet" type="text/css" href="css/main.css">
    <style type="text/css">
        .brand {
            width: 1200px;
            height: auto;
            margin: 10px auto;
        }

        .part {
            margin-top: 30px;
            width: 1200px;
            height: 407px;
            border: 1px solid #ccc;
        }

        .content {
            width: 350px;
            height: auto;
            display: inline-block;
            position: absolute;
            margin-top: 120px;
            margin-left: 50px;
        }

        .buy {
            width: 150px;
            height: 45px;
            background-color: #FC5558;
            margin-top: 15px;
            font-size: 15px;
            font-weight: bolder;
            color: white;
            border: none;
            border-radius: 10px;
        }

        .buy:hover {
            background-color: red;
        }
    </style>
</head>
<body>
<%
    request.setCharacterEncoding("utf-8");
    Dao dao = new Dao();
    String search = request.getParameter("search");
    Object user_login = request.getSession().getAttribute("user_login");
    Object administrators_login = request.getSession().getAttribute("administrators_login");
    System.out.println(user_login);
    System.out.println(administrators_login);
    if (search == null) {
        List<Goods> allGoods = dao.findAllGoods();
        request.setAttribute("goods_search", allGoods);
    } else {
        List<Goods> goodsBySearch = dao.findGoodsBySearch(search);
        if (goodsBySearch.size() == 0) {
            out.print("<script>");
            out.print("alert(\"未查询到该品牌商品\")");
            out.print("</script>");
            List<Goods> allGoods = dao.findAllGoods();
            request.setAttribute("goods_search", allGoods);
        } else {
            request.setAttribute("goods_search", goodsBySearch);
        }
    }
%>
<div class="logoBar">
    <div class="comWidth" style="display: block;">
        <form class="search_box fl" style="display: block;" method="post"
              action="${pageContext.request.contextPath}/index.jsp">
            <input type="text" placeholder="请输入搜索的商品品牌" class="search_text fl" id="search" name="search">
            <input type="submit" value="搜 索" class="search_button fr">
        </form>
        <c:if test="${user_login==null}">
            <a href="${pageContext.request.contextPath}/userLogin.jsp">
                <button type="button" class="btn btn-default" style="float: right;margin-top: 23px;margin-right: 2px;">
                    登录
                </button>
            </a>
        </c:if>
        <c:if test="${user_login!=null}">
            <div class="btn-group" style="float: right;margin-top: 23px;margin-right: 2px;">
                <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown"
                        aria-haspopup="true" aria-expanded="false">
                        ${user_login.username} <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    <li><a href="${pageContext.request.contextPath}/findUserByIdServlet?id=${user_login.id}">修改资料</a>
                    </li>
                    <li><a href="${pageContext.request.contextPath}/findAllOrderServlet?id=${user_login.id}">查询订单</a>
                    </li>
                    <li><a href="${pageContext.request.contextPath}/ShoppingCarList.jsp?id=${user_login.id}">查询购物车</a>
                    </li>
                    <li><a href="${pageContext.request.contextPath}/outUserLoginServlet">注销登录</a></li>
                </ul>
            </div>
        </c:if>
    </div>
</div>
<c:forEach items="${goods_search}" var="good" varStatus="s">
    <div class="brand">
        <div class="part">
            <img src="${good.cimage}" alt="" style="width: 800px;height: 407px;text-align: left;">
            <div class="content">
                <p style="font-size: 22px;font-weight: bolder;">${good.cname}</p>
                <p style="font-size: 15px;color: darkgrey;">${good.cname_no2}</p>
                <p style="font-size: 25px;color: #FC5558;font-weight: bolder;margin-top: 35px;">￥${good.cprice}</p>
                <a href="${pageContext.request.contextPath}/searchGoodInfoServlet?cid=${good.cid}"><input class="buy"
                                                                                                          type="submit"
                                                                                                          value="立即购买"></a>
            </div>
        </div>
    </div>
</c:forEach>
</body>
</html>
